﻿using System;
using System.Linq;
using CI.Models.Data;
using CI.Services;
using CI.ViewModels.Diagramming;
using Microsoft.Practices.ServiceLocation;

namespace CI.ViewModels
{
    public class OwnerSelectorViewModel : ItemSelectorViewModelBase
    {
        private readonly IOwnerService _ownerService = ServiceLocator.Current.GetInstance<IOwnerService>();

        public OwnerSelectorViewModel(string groupName, DiagramViewModel parentViewModel) : base(groupName, parentViewModel)
        {
            foreach (var corp in _ownerService.Corporations)
                Items.Add(corp);
            foreach (var character in _ownerService.Characters)
                Items.Add(character);
        }

        protected override void ApplyFilter()
        {
            Items.Clear();

            foreach (var c in _ownerService.Corporations.Where(a => a.Name.IndexOf(FilterByName) > -1))
                Items.Add(c);

            foreach (var c in _ownerService.Characters.Where(a=>a.Name.IndexOf(FilterByName) > -1))
                Items.Add(c);
        }
    }
}
